export default {
    namespaced: true, // 命名空間

    state: {
        userInfo: {
            name: 'hsz',
            token: 'hsz-token'
        }
    },

    getters: {
        gettersUserInfo(state) { // -> getters['user/gettersUserInfo']
            return (
                'name: ' + state.userInfo.name + ',token: ' + state.userInfo.token
            )
        }
    },

    mutations: {
        updateName(state) { // -> mutations['user/updateName']
            state.userInfo.name += '1'
        }
    },
    // 包裹mutations，使之可以异步
    actions: {
        updateNameAction(context) { // -> actions['user/updateNameAction']
            setTimeout(() => {
                context.commit('updateName')
            }, 500)
        }
    }
}
